//
//  GWAppUIContentViewNavigationBar.m
//  GameSky
//
//  Created by lanou on 16/1/11.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GWAppUIContentViewNavigationBar.h"

@implementation GWAppUIContentViewNavigationBar
#pragma mark-----------自定义初始化------------
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        // 添加子控件
        [self addSubviews];
    }
    return self;
}
#pragma mark----------添加控件-----------------
- (void)addSubviews{
    self.backgroundColor = [UIColor colorWithRed:155/255.0 green:37/255.0 blue:34/255.0 alpha:1.0];
// 返回按钮
    _BackButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _BackButton.frame = CGRectMake(5, 20, 40, 40);
    //_BackButton.backgroundColor = [UIColor greenColor];
    [_BackButton setImage:[UIImage imageNamed:@"common_Icon_Back_20x20_UIMode_Day@2x"] forState:(UIControlStateNormal)];
    [self addSubview:_BackButton];
// 搜索按钮
    _SearchButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _SearchButton.frame = CGRectMake(kScreenWidth - 40 - 5, 20, 40, 40);
    [_SearchButton setImage:[UIImage imageNamed:@"common_Icon_Search_20x20_UIMode_Day@2x"] forState:(UIControlStateNormal)];
    [self addSubview:_SearchButton];
// 中间 展示标签的 label
    _middleLabel = [[UILabel alloc] initWithFrame:CGRectMake(_BackButton.right + 4, _BackButton.top + 2,_SearchButton.left - 4 - _BackButton.right - 4, _SearchButton.height - 2)];
    _middleLabel.userInteractionEnabled = YES;
    [self addSubview:_middleLabel];
// 循环创建 三个Label(热门,全部,我的)
    for (int i = 0; i < 3; i++) {
        CGFloat width = (_middleLabel.width - 120 - 60) / 2;
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        button.frame = CGRectMake(width + (i * 70), (_middleLabel.height - 22) / 2, 40, 22);
        button.tag = 100 + i;
// button添加方法
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
        button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [_middleLabel addSubview:button];
    }
    // 与三个button属性关联
    _hotButton = (UIButton *)[self viewWithTag:100];
    [_hotButton setTitle:@"热门" forState:(UIControlStateNormal)];;
    _allButton = (UIButton *)[self viewWithTag:101];
    [_allButton setTitle:@"全部" forState:(UIControlStateNormal)];
    _mineButton = (UIButton *)[self viewWithTag:102];
    [_mineButton setTitle:@"我的" forState:(UIControlStateNormal)];
}

// 点击方法
- (void)buttonAction:(UIButton *)button{
    self.block(button.tag);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
